package com.captain.leetcode.二叉树;

import com.captain.leetcode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author captain
 * @Des 先左叶子节点 - 再父节点 - 右节点
 * @Date 2021/7/20 21:10
 */
public class 二叉树的中序遍历94 {

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        middleOrder(root, res);
        return res;
    }

    public void middleOrder(TreeNode tree, List<Integer> res) {
        //先左叶子节点 - 再父节点 - 右节点
        //结束条件
        if (tree == null) return;
        //向左节点遍历
        middleOrder(tree.left, res);
        //左侧遍历结束
        res.add(tree.val);
        //朝右遍历
        middleOrder(tree.right,res);
    }
}
